package com.jeff.tianti.controller.channel;

import com.jeff.tianti.cms.entity.TalentPool;
import com.jeff.tianti.cms.service.TalentPoolService;
import com.jeff.tianti.common.dto.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/channel/talent")//江苏频道_人才库模块
@CrossOrigin(maxAge = 3600)
public class TalentPoolController {
    @Autowired
    private TalentPoolService talentPoolService;
    /**
     * @Ceator:liuYI
     * @Describe:江苏频道_人才库模块人才数据列表
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public AjaxResult findAll() {
        List<TalentPool> talentPools = talentPoolService.queryTalentPoolList(null);
        Map<String, List<TalentPool>> map = talentPools.stream().collect(Collectors.groupingBy(TalentPool::getTalentTypeName));
        Set<String> set = map.keySet();
        Map<Object, Object> result = new HashMap<>();
        set.stream().forEach(t ->
                result.put(t, map.get(t).stream().collect(Collectors.groupingBy(TalentPool::getTypeName))));
        return AjaxResult.setSuccessData(result);
    }

    /**
     * @Ceator:liuYI
     * @Describe:江苏频道_人才库_详情查看
     */
    @RequestMapping(value = "/details", method = RequestMethod.GET)
    public AjaxResult findById(@RequestParam("id") String id) {
        TalentPool talentPool = talentPoolService.find(id);
        return AjaxResult.setSuccessData(talentPool);
    }
}
